<?php
/**
*	@package UHU_Apps
*	@subpackage Ping
**/

uhu::load_components('ping-package');

/**
*	@package UHU_exception
*	@subpackage Pinerati
**/
class pingerati_exception extends uhu_exception
{
	protected function getExtendedMessage($code=null)
	{
		$message = '%s';
		switch($code)
		{
			case 100:
			case 101:
				$message = 'Could not execute ping: %s';
			break;
			
			case 200:
				$message = 'Could not add pingerati sub-service: %s';
			break;
		}
		return $message;
	}
}

/**
*	@package Ping_package_pinger
*	@subpackage Pinerati_type
**/
abstract class pingerati_type extends ping_package_pinger
{
	abstract protected function root_url();
	protected function url(ping_package $ping_package)
	{
		return $this->root_url() . $ping_package->resource();
	}
	public function update(SplSubject $Subject)
	{
		$curl = uhu::curl($this->url($Subject),'GET',array(CURLOPT_NOBODY=>true),null,array(CURLINFO_HTTP_CODE));
		if(isset($curl->info,$curl->info[CURLINFO_HTTP_CODE]) === false)
		{
			throw new ping_package_exception('Could not get HTTP status of ping request for ' . get_class($this) . ' type',100);
		}
		else if($curl->info[CURLINFO_HTTP_CODE] !== 200)
		{
			throw new ping_package_exception('HTTP status of ping request for ' . get_class($this) . ' type not 200, \'' . (string)$curl->info[CURLINFO_HTTP_CODE] . '\' given.',101);
		}
		else
		{
			return true;
		}
	}
}

/**
*	@package Pingerati
*	@subpackage Pinerati_type
**/
class pingerati_type_general extends pingerati_type
{
	protected function root_url()
	{
		return 'http://pingerati.net/ping/';
	}
}

/**
*	@package Pingerati
*	@subpackage Pinerati_type
**/
class pingerati_type_hCard extends pingerati_type
{
	protected function root_url()
	{
		return 'http://contacts.pingerati.net/ping/';
	}
}

/**
*	@package Pingerati
*	@subpackage Pinerati_type
**/
class pingerati_type_hCalendar extends pingerati_type
{
	protected function root_url()
	{
		return 'http://events.pingerati.net/ping/';
	}
}

/**
*	@package Pingerati
*	@subpackage Pinerati_type
**/
class pingerati_type_hReview extends pingerati_type
{
	protected function root_url()
	{
		return 'http://reviews.pingerati.net/ping/';
	}
}

/**
*	@package Pingerati
*	@subpackage Pinerati_type
**/
class pingerati_type_hListing extends pingerati_type
{
	protected function root_url()
	{
		return 'http://listings.pingerati.net/ping/';
	}
}

/**
*	@package Pingerati
*	@subpackage Pinerati_type
**/
class pingerati_type_xFolk extends pingerati_type
{
	protected function root_url()
	{
		return 'http://links.pingerati.net/ping/';
	}
}

/**
*	@package Ping_package
*	@subpackage Pinerati
**/
class pingerati extends ping_package
{
	protected $resource;
	protected $observers = array();
	public function __construct($resource)
	{
		$this->resource = $resource;
	}
	public function resource()
	{
		return $this->resource;
	}
}
?>